<%@page import="cn.edu.nju.ws.sview.views.User"%>
<%@page import="cn.edu.nju.ws.sview.views.Group"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Group Profile</title>
    <link rel="icon" href="/sview/favicon.ico" />
    <meta content="text/html" />
	
	<script type="text/javascript" src="/sview/script/jquery.js"></script>
	<script type="text/javascript" src="/sview/script/group/gprofile.js"></script>
	<script type="text/javascript" src="/sview/script/global.js"></script>

  	<link rel="stylesheet" href="../css/group/bootstrap-responsive.min.css" type="text/css"></link>
  	<link rel="stylesheet" href="../css/group/bootstrap.min.css" type="text/css"></link>
	<link rel="stylesheet" type="text/css" href="/sview/css/layout.css" />
  	<link rel="stylesheet" href="../css/group/gprofile.css" type="text/css"></link>
  
  </head>
  <%
  	String lang = request.getParameter("lang");
       if (lang != null && lang.equals("zh")) {
			request.getRequestDispatcher("gprofile_zh.jsp").forward(
					request, response);
		} else if (lang == null) {
			lang = "en";
		}
  	String gid = request.getParameter("gid");
  	String gName = null;
  	if(gid != null){
  		gName = Group.getGroupNameById(Integer.parseInt(gid));
  	}else{
  		response.sendRedirect("/sview/views/index.jsp?lang="+lang);
  		return;
  	}
  	String uName = (String)session.getAttribute("user");
	String ugname = (String)session.getAttribute("groupName");
  	int ugid = -1;
	if(ugname != null){
		ugid = Group.getGroupIdByName(ugname);
	}
	Boolean isGroup = (ugid==(Integer.parseInt(gid)));
  	boolean isMember = false;
	if(uName != null){
  		isMember = Group.isMember(Integer.parseInt(gid), User.getUserIdByName(uName));
	}
  	String flag="";
  	if(User.getUserIdByName((Group.getAdmin(Integer.parseInt(gid)))) == User.getUserIdByName(uName)){ 
  		flag="admin";
  	}else if(isGroup){
  		flag="isGroup";
  	}else{
  		flag="member";
  	}
  	String btnText = "";
   %>
  <body>
   <jsp:include page="/vheader.jsp" flush="true" />
      <div class="metaInfo">
      	<span class="logoSpan"><img id="groupLogo" src="/sview/css/images/user_normal.jpg" width="48px" height="48px" alt="logol" /></span>
      	<span class="titleSpan"><%=gName %></span>
      	<%
      	if(isMember && uName!=null){ 
      		btnText = "Leave";%>
      		<span class="btnSpan"><input type="button" value="<%=btnText %>" id="operateBtn" class="btn btn-small btn-primary" onclick="return leave();" style="vertical-align: bottom;margin-left: 20px;"/></span>
      	<%}else if(uName!=null){
      		btnText = "Join in"; %>
      		<span class="btnSpan"><input type="button" value="<%=btnText %>" id="operateBtn" class="btn btn-small btn-primary" onclick="return join();" style="vertical-align: bottom;margin-left: 20px;"/></span>
      	<%}%>
      </div>
      <div class="Content row-fluid">
      	<div class="navDiv span9">
	      	<ul class="nav nav-tabs">
			  <li id="homeNav" class="active">
			    <a href="#">Home</a>
			  </li>
			  <li id="artifactsNav"><a href="#">Arifacts</a></li>
			</ul>
      	</div>
      	<div id="homeDiv" class="panel row-fluid">
      	     <div id="detailNav_gh" class="detailNavDiv span" style="font-size: 12px;">
      	     	<ul class="nav nav-pills">
				  <li id="summaryNav" class="active">
				    <a href="#">Summary</a>
				  </li>
				  <li id="membersNav"><a href="#">Members</a></li>
				</ul>
      	     </div>
      	     <div id="summaryDiv" class="panel span">
      	     </div>
      	     <div id="membersDiv" class="panel span origin" style="display:none;">
      	     	<table>
      	     	</table>
      	     </div>
      	</div>
      	<div id="artifactsDiv" class="panel row-fluid" style="display:none;">
      		<div id="detailNav_ga" class="detailNavDiv span" style="font-size: 12px;">
      	     	<ul class="nav nav-pills">
				  <li id="entitiesNav" class="active">
				    <a href="#">Entities</a>
				  </li>
				  <li id="viewsNav"><a href="#">Views</a></li>
				  <li id="datasetsNav"><a href="#">Datasets</a></li>
				  <li id="relationsNav"><a href="#">Relations</a></li>
				</ul>
      	     </div>
      	      <div id="entitiesDiv" class="panel span">
      	     	<table>
      	     	</table>
      	     </div>
      	     <div id="viewsDiv" class="panel span origin" style="display:none;">
      	     	<table>
      	     	</table>
      	     </div>
      	     <div id="datasetsDiv" class="panel span origin" style="display:none;">
      	     	<table>
      	     	</table>
      	     </div>
      	     <div id="relationsDiv" class="panel span origin" style="display:none;">
      	     	<table>
      	     	</table>
      	     </div>
      	</div>
      </div> 
   <%
   	if(uName!=null){
    %>
<!--     <input type="hidden" id="" /> -->
    <%} %>
   <input type="hidden" id="gid" value="<%=gid %>" />   
   <input type="hidden" id="uid" value="<%=User.getUserIdByName(uName) %>" />
   <input type="hidden" id="gname" value="<%= Group.getGroupNameById(Integer.parseInt(gid)) %>" />   
   <input type="hidden" id="uname" value="<%= uName %>" />  
   <input type="hidden" id="flag" value="<%= flag %>" />  
   <input type="hidden" id="display-lang" value="<%= lang %>"/>  
   <jsp:include page="/vfooter.jsp"></jsp:include>  

  </body>
</html>
